package com.itheima.day815.test;

import com.itheima.domain.Student;

import java.util.ArrayList;
import java.util.Scanner;

public class Demo3Student {
    public static void main(String[] args) {
        ArrayList<Student>list = new ArrayList<>();
        Student stu1 = getStudent(1);
        Student stu2 = getStudent(2);
        Student stu3 = getStudent(3);
        //往集合中添加对象
        list.add(stu1);
        list.add(stu2);
        list.add(stu3);
        //循环遍历
        for (int i = 0; i < list.size(); i++) {
            Student stu = list.get(i);
            System.out.println(stu.getName()+"..."+stu.getAge());
        }
    }

    public static Student getStudent(int count) {
        Scanner sc =new Scanner(System.in);
        //提示语句
        System.out.println("请输入第个"+count+"学生姓名");
        String name = sc.next();
        System.out.println("请输入第个"+count+"学生年龄");
        int age = sc.nextInt();
        Student stu =new Student(name,age);
        return stu;
    }
}
